home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 64
/
Volume 64 - JOGO DISK .iso
/
Games
/
the_best_every_day.swf
/
scripts
/
__Packages
/
MiniGame.as
< prev
next >
Wrap
Text File
|
2008-04-10
|
5KB
|
152 lines
class MiniGame extends MovieClip
{
var DEFAULT_STATE = "update";
var TIME_RANDOM = 200;
var aKeyPossible = ["81","87","82","84","80","76","75","74","72","71","70","68","83"];
function MiniGame()
{
super();
_global.C.oGame.mcMiniGame = _global.C.oGame.mcGame.MiniGame;
_global.MiniGame = this;
this.keyListener = new Object();
this.nKeyUsed = 0;
this.nTimeWait = 0;
this.sEtat = "Wait";
this.setVars();
}
function update()
{
this[this.sEtat]();
}
function setVars()
{
this.nTimeToWait = _global.C.oGame.nTimeBetweenMG + random(this.TIME_RANDOM);
}
function Wait()
{
this.nTimeWait = this.nTimeWait + 1;
if(this.nTimeWait > this.nTimeToWait && _global.C.oGame.oLevel.oPatrick.sState == "Move")
{
this.nTimeWait = 0;
this.ActionDone = 0;
this.nKeyToUse = 0;
this.setVars();
this.PrepareStage();
var _loc3_ = random(100);
if(_loc3_ < 33 && this.nElementToUse != 1)
{
this.RepeatAction = 15;
this.nElementToUse = 1;
}
else if(_loc3_ < 66 && this.nElementToUse != 2)
{
this.RepeatAction = 7;
this.nElementToUse = 2;
}
else if(this.nElementToUse != 3)
{
this.RepeatAction = 4;
this.nElementToUse = 3;
}
else
{
this.RepeatAction = 7;
this.nElementToUse = 2;
}
this.mcRef.gotoAndStop(this.nElementToUse);
this.CreateArray();
this.sEtat = "Pass";
}
}
function CreateArray()
{
this.aKeyToActive = new Array();
var _loc3_ = Tools.doCopyArray(this.aKeyPossible);
while(this.aKeyToActive.length < this.nElementToUse)
{
var _loc2_ = random(_loc3_.length);
this.mcRef["Key" + this.aKeyToActive.length].Key_txt.text = String.fromCharCode(_loc3_[_loc2_]);
if(this.aKeyToActive.length == 0)
{
this.mcRef.Window_txt.text += String(this.mcRef["Key" + this.aKeyToActive.length].Key_txt.text);
this.mcRef["Key" + this.aKeyToActive.length].gotoAndStop(2);
}
else
{
this.mcRef.Window_txt.text += ", " + String(this.mcRef["Key" + this.aKeyToActive.length].Key_txt.text);
}
this.aKeyToActive.push(_loc3_[_loc2_]);
_loc3_.splice(_loc2_,1);
}
}
function PrepareStage()
{
_global.C.oGame.bMiniGame = true;
_global.C.oGame.oLevel.oPatrick.mc._parent._parent.mcSpongebob.gotoAndStop("OffScreen");
_global.C.oGame.mcGame.MiniGame.gotoAndPlay("appear");
this.mcRef = _global.C.oGame.mcGame.MiniGame.GameScreen;
this.mcRef.Barre._xscale = 0;
this.CreateOnPress();
}
function Pass()
{
if(this.nKeyUsed != 0)
{
this.CheckActionEnter();
this.nKeyUsed = 0;
if(this.ActionDone == this.RepeatAction)
{
this.Succead();
}
}
}
function CheckActionEnter()
{
if(this.nKeyUsed == this.aKeyToActive[this.nKeyToUse])
{
this.mcRef["Key" + this.nKeyToUse].gotoAndStop(1);
this.nKeyToUse = this.nKeyToUse + 1;
this.mcRef.Barre._xscale = Number((this.nKeyToUse + this.ActionDone * this.nElementToUse) / (this.RepeatAction * this.nElementToUse) * 100);
if(this.nKeyToUse >= this.aKeyToActive.length)
{
this.nKeyToUse = 0;
this.ActionDone = this.ActionDone + 1;
}
this.mcRef["Key" + this.nKeyToUse].gotoAndStop(2);
}
}
function CheckButtonEnter(_code)
{
if(_code == this.aKeyToActive[this.nKeyToUse])
{
this.mcRef["Key" + this.nKeyToUse].gotoAndStop(3);
}
}
function Succead()
{
this.sEtat = "Wait";
this.mcRef.gotoAndStop(Number(this.mcRef._currentframe + 3));
_global.C.oGame.AjustScore(_global.C.oGame.nMiniFunds,"Funds");
_global.C.oGame.oLevel.oPatrick.mc._parent._parent.mcSpongebob.gotoAndStop("inScreen");
_global.C.oGame.mcGame.MiniGame.gotoAndPlay("disapear");
_global.C.oGame.bMiniGame = false;
this.ClearControls();
}
function CreateOnPress()
{
this.keyListener.onKeyUp = function()
{
_global.MiniGame.nKeyUsed = Key.getCode();
};
this.keyListener.onKeyDown = function()
{
_global.MiniGame.CheckButtonEnter(Key.getCode());
};
Key.addListener(this.keyListener);
}
function ClearControls()
{
Key.removeListener(this.keyListener);
}
}